// pages/feedback/feedback.js
const http = require("../../utils/http")
const sto = require("../../utils/sto")
const api = require("../../comm/api")

import Notify from "../../components/@vant/weapp/notify/notify"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    error_title: '',
    error_content: '',
    isLoading: false
  },

  onSubmit: function (e) {
    const params = e.detail.value
    const title_valied = !!params.title
    const content_valied = !!params.content
    this.setData({
      error_title: title_valied ? "" : "标题不能为空",
      error_content: content_valied ? "" : "内容不能为空",
    })
    if (title_valied && content_valied) {
      this.setData({
        isLoading: true
      })
      http.postJSONWithToken(api.Feedback.Add.PATH, params, pojo => {
        Notify({
          type: 'success',
          message: '意见反馈提交成功！',
          onClose: () => {
            wx.navigateBack({
              delta: 0,
            })
          }
        })
      }, err => {
        Notify({
          type: 'warning',
          message: JSON.stringify(err)
        })
        this.setData({
          isLoading: false
        })
      })
    }
  }
})